// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ml
{
	public sealed class MlPutTrainedModelRequestParameters : RequestParameters<MlPutTrainedModelRequestParameters>
	{
		[JsonIgnore]
		public bool? DeferDefinitionDecompression { get => Q<bool?>("defer_definition_decompression"); set => Q("defer_definition_decompression", value); }
	}

	public sealed partial class MlPutTrainedModelRequest : PlainRequestBase<MlPutTrainedModelRequestParameters>
	{
		public MlPutTrainedModelRequest(Elastic.Clients.Elasticsearch.Id model_id) : base(r => r.Required("model_id", model_id))
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPutTrainedModel;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		[JsonIgnore]
		public bool? DeferDefinitionDecompression { get => Q<bool?>("defer_definition_decompression"); set => Q("defer_definition_decompression", value); }

		[JsonInclude]
		[JsonPropertyName("compressed_definition")]
		public string? CompressedDefinition { get; set; }

		[JsonInclude]
		[JsonPropertyName("definition")]
		public Elastic.Clients.Elasticsearch.Ml.Definition? Definition { get; set; }

		[JsonInclude]
		[JsonPropertyName("description")]
		public string? Description { get; set; }

		[JsonInclude]
		[JsonPropertyName("inference_config")]
		public Elastic.Clients.Elasticsearch.Ml.InferenceConfigCreateContainer InferenceConfig { get; set; }

		[JsonInclude]
		[JsonPropertyName("input")]
		public Elastic.Clients.Elasticsearch.Ml.Input Input { get; set; }

		[JsonInclude]
		[JsonPropertyName("metadata")]
		public object? Metadata { get; set; }

		[JsonInclude]
		[JsonPropertyName("model_type")]
		public Elastic.Clients.Elasticsearch.Ml.TrainedModelType? ModelType { get; set; }

		[JsonInclude]
		[JsonPropertyName("model_size_bytes")]
		public long? ModelSizeBytes { get; set; }

		[JsonInclude]
		[JsonPropertyName("tags")]
		public IEnumerable<string>? Tags { get; set; }
	}

	public sealed partial class MlPutTrainedModelRequestDescriptor<TDocument> : RequestDescriptorBase<MlPutTrainedModelRequestDescriptor<TDocument>, MlPutTrainedModelRequestParameters>
	{
		internal MlPutTrainedModelRequestDescriptor(Action<MlPutTrainedModelRequestDescriptor<TDocument>> configure) => configure.Invoke(this);
		public MlPutTrainedModelRequestDescriptor(Elastic.Clients.Elasticsearch.Id model_id) : base(r => r.Required("model_id", model_id))
		{
		}

		internal MlPutTrainedModelRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPutTrainedModel;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		public MlPutTrainedModelRequestDescriptor<TDocument> DeferDefinitionDecompression(bool? deferDefinitionDecompression = true) => Qs("defer_definition_decompression", deferDefinitionDecompression);
		public MlPutTrainedModelRequestDescriptor<TDocument> ModelId(Elastic.Clients.Elasticsearch.Id model_id)
		{
			RouteValues.Required("model_id", model_id);
			return Self;
		}

		private Elastic.Clients.Elasticsearch.Ml.Definition? DefinitionValue { get; set; }

		private DefinitionDescriptor<TDocument> DefinitionDescriptor { get; set; }

		private Action<DefinitionDescriptor<TDocument>> DefinitionDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.InferenceConfigCreateContainer InferenceConfigValue { get; set; }

		private InferenceConfigCreateContainerDescriptor<TDocument> InferenceConfigDescriptor { get; set; }

		private Action<InferenceConfigCreateContainerDescriptor<TDocument>> InferenceConfigDescriptorAction { get; set; }

		private string? CompressedDefinitionValue { get; set; }

		private string? DescriptionValue { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.Input InputValue { get; set; }

		private InputDescriptor InputDescriptor { get; set; }

		private Action<InputDescriptor> InputDescriptorAction { get; set; }

		private object? MetadataValue { get; set; }

		private long? ModelSizeBytesValue { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.TrainedModelType? ModelTypeValue { get; set; }

		private IEnumerable<string>? TagsValue { get; set; }

		public MlPutTrainedModelRequestDescriptor<TDocument> Definition(Elastic.Clients.Elasticsearch.Ml.Definition? definition)
		{
			DefinitionDescriptor = null;
			DefinitionDescriptorAction = null;
			DefinitionValue = definition;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> Definition(DefinitionDescriptor<TDocument> descriptor)
		{
			DefinitionValue = null;
			DefinitionDescriptorAction = null;
			DefinitionDescriptor = descriptor;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> Definition(Action<DefinitionDescriptor<TDocument>> configure)
		{
			DefinitionValue = null;
			DefinitionDescriptor = null;
			DefinitionDescriptorAction = configure;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> InferenceConfig(Elastic.Clients.Elasticsearch.Ml.InferenceConfigCreateContainer inferenceConfig)
		{
			InferenceConfigDescriptor = null;
			InferenceConfigDescriptorAction = null;
			InferenceConfigValue = inferenceConfig;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> InferenceConfig(InferenceConfigCreateContainerDescriptor<TDocument> descriptor)
		{
			InferenceConfigValue = null;
			InferenceConfigDescriptorAction = null;
			InferenceConfigDescriptor = descriptor;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> InferenceConfig(Action<InferenceConfigCreateContainerDescriptor<TDocument>> configure)
		{
			InferenceConfigValue = null;
			InferenceConfigDescriptor = null;
			InferenceConfigDescriptorAction = configure;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> CompressedDefinition(string? compressedDefinition)
		{
			CompressedDefinitionValue = compressedDefinition;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> Description(string? description)
		{
			DescriptionValue = description;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> Input(Elastic.Clients.Elasticsearch.Ml.Input input)
		{
			InputDescriptor = null;
			InputDescriptorAction = null;
			InputValue = input;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> Input(InputDescriptor descriptor)
		{
			InputValue = null;
			InputDescriptorAction = null;
			InputDescriptor = descriptor;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> Input(Action<InputDescriptor> configure)
		{
			InputValue = null;
			InputDescriptor = null;
			InputDescriptorAction = configure;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> Metadata(object? metadata)
		{
			MetadataValue = metadata;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> ModelSizeBytes(long? modelSizeBytes)
		{
			ModelSizeBytesValue = modelSizeBytes;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> ModelType(Elastic.Clients.Elasticsearch.Ml.TrainedModelType? modelType)
		{
			ModelTypeValue = modelType;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor<TDocument> Tags(IEnumerable<string>? tags)
		{
			TagsValue = tags;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (DefinitionDescriptor is not null)
			{
				writer.WritePropertyName("definition");
				JsonSerializer.Serialize(writer, DefinitionDescriptor, options);
			}
			else if (DefinitionDescriptorAction is not null)
			{
				writer.WritePropertyName("definition");
				JsonSerializer.Serialize(writer, new DefinitionDescriptor<TDocument>(DefinitionDescriptorAction), options);
			}
			else if (DefinitionValue is not null)
			{
				writer.WritePropertyName("definition");
				JsonSerializer.Serialize(writer, DefinitionValue, options);
			}

			if (InferenceConfigDescriptor is not null)
			{
				writer.WritePropertyName("inference_config");
				JsonSerializer.Serialize(writer, InferenceConfigDescriptor, options);
			}
			else if (InferenceConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("inference_config");
				JsonSerializer.Serialize(writer, new InferenceConfigCreateContainerDescriptor<TDocument>(InferenceConfigDescriptorAction), options);
			}
			else
			{
				writer.WritePropertyName("inference_config");
				JsonSerializer.Serialize(writer, InferenceConfigValue, options);
			}

			if (!string.IsNullOrEmpty(CompressedDefinitionValue))
			{
				writer.WritePropertyName("compressed_definition");
				writer.WriteStringValue(CompressedDefinitionValue);
			}

			if (!string.IsNullOrEmpty(DescriptionValue))
			{
				writer.WritePropertyName("description");
				writer.WriteStringValue(DescriptionValue);
			}

			if (InputDescriptor is not null)
			{
				writer.WritePropertyName("input");
				JsonSerializer.Serialize(writer, InputDescriptor, options);
			}
			else if (InputDescriptorAction is not null)
			{
				writer.WritePropertyName("input");
				JsonSerializer.Serialize(writer, new InputDescriptor(InputDescriptorAction), options);
			}
			else
			{
				writer.WritePropertyName("input");
				JsonSerializer.Serialize(writer, InputValue, options);
			}

			if (ModelSizeBytesValue.HasValue)
			{
				writer.WritePropertyName("model_size_bytes");
				writer.WriteNumberValue(ModelSizeBytesValue.Value);
			}

			if (ModelTypeValue is not null)
			{
				writer.WritePropertyName("model_type");
				JsonSerializer.Serialize(writer, ModelTypeValue, options);
			}

			if (TagsValue is not null)
			{
				writer.WritePropertyName("tags");
				JsonSerializer.Serialize(writer, TagsValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class MlPutTrainedModelRequestDescriptor : RequestDescriptorBase<MlPutTrainedModelRequestDescriptor, MlPutTrainedModelRequestParameters>
	{
		internal MlPutTrainedModelRequestDescriptor(Action<MlPutTrainedModelRequestDescriptor> configure) => configure.Invoke(this);
		public MlPutTrainedModelRequestDescriptor(Elastic.Clients.Elasticsearch.Id model_id) : base(r => r.Required("model_id", model_id))
		{
		}

		internal MlPutTrainedModelRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPutTrainedModel;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		public MlPutTrainedModelRequestDescriptor DeferDefinitionDecompression(bool? deferDefinitionDecompression = true) => Qs("defer_definition_decompression", deferDefinitionDecompression);
		public MlPutTrainedModelRequestDescriptor ModelId(Elastic.Clients.Elasticsearch.Id model_id)
		{
			RouteValues.Required("model_id", model_id);
			return Self;
		}

		private Elastic.Clients.Elasticsearch.Ml.Definition? DefinitionValue { get; set; }

		private DefinitionDescriptor DefinitionDescriptor { get; set; }

		private Action<DefinitionDescriptor> DefinitionDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.InferenceConfigCreateContainer InferenceConfigValue { get; set; }

		private InferenceConfigCreateContainerDescriptor InferenceConfigDescriptor { get; set; }

		private Action<InferenceConfigCreateContainerDescriptor> InferenceConfigDescriptorAction { get; set; }

		private string? CompressedDefinitionValue { get; set; }

		private string? DescriptionValue { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.Input InputValue { get; set; }

		private InputDescriptor InputDescriptor { get; set; }

		private Action<InputDescriptor> InputDescriptorAction { get; set; }

		private object? MetadataValue { get; set; }

		private long? ModelSizeBytesValue { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.TrainedModelType? ModelTypeValue { get; set; }

		private IEnumerable<string>? TagsValue { get; set; }

		public MlPutTrainedModelRequestDescriptor Definition(Elastic.Clients.Elasticsearch.Ml.Definition? definition)
		{
			DefinitionDescriptor = null;
			DefinitionDescriptorAction = null;
			DefinitionValue = definition;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor Definition(DefinitionDescriptor descriptor)
		{
			DefinitionValue = null;
			DefinitionDescriptorAction = null;
			DefinitionDescriptor = descriptor;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor Definition(Action<DefinitionDescriptor> configure)
		{
			DefinitionValue = null;
			DefinitionDescriptor = null;
			DefinitionDescriptorAction = configure;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor InferenceConfig(Elastic.Clients.Elasticsearch.Ml.InferenceConfigCreateContainer inferenceConfig)
		{
			InferenceConfigDescriptor = null;
			InferenceConfigDescriptorAction = null;
			InferenceConfigValue = inferenceConfig;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor InferenceConfig(InferenceConfigCreateContainerDescriptor descriptor)
		{
			InferenceConfigValue = null;
			InferenceConfigDescriptorAction = null;
			InferenceConfigDescriptor = descriptor;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor InferenceConfig(Action<InferenceConfigCreateContainerDescriptor> configure)
		{
			InferenceConfigValue = null;
			InferenceConfigDescriptor = null;
			InferenceConfigDescriptorAction = configure;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor CompressedDefinition(string? compressedDefinition)
		{
			CompressedDefinitionValue = compressedDefinition;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor Description(string? description)
		{
			DescriptionValue = description;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor Input(Elastic.Clients.Elasticsearch.Ml.Input input)
		{
			InputDescriptor = null;
			InputDescriptorAction = null;
			InputValue = input;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor Input(InputDescriptor descriptor)
		{
			InputValue = null;
			InputDescriptorAction = null;
			InputDescriptor = descriptor;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor Input(Action<InputDescriptor> configure)
		{
			InputValue = null;
			InputDescriptor = null;
			InputDescriptorAction = configure;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor Metadata(object? metadata)
		{
			MetadataValue = metadata;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor ModelSizeBytes(long? modelSizeBytes)
		{
			ModelSizeBytesValue = modelSizeBytes;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor ModelType(Elastic.Clients.Elasticsearch.Ml.TrainedModelType? modelType)
		{
			ModelTypeValue = modelType;
			return Self;
		}

		public MlPutTrainedModelRequestDescriptor Tags(IEnumerable<string>? tags)
		{
			TagsValue = tags;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (DefinitionDescriptor is not null)
			{
				writer.WritePropertyName("definition");
				JsonSerializer.Serialize(writer, DefinitionDescriptor, options);
			}
			else if (DefinitionDescriptorAction is not null)
			{
				writer.WritePropertyName("definition");
				JsonSerializer.Serialize(writer, new DefinitionDescriptor(DefinitionDescriptorAction), options);
			}
			else if (DefinitionValue is not null)
			{
				writer.WritePropertyName("definition");
				JsonSerializer.Serialize(writer, DefinitionValue, options);
			}

			if (InferenceConfigDescriptor is not null)
			{
				writer.WritePropertyName("inference_config");
				JsonSerializer.Serialize(writer, InferenceConfigDescriptor, options);
			}
			else if (InferenceConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("inference_config");
				JsonSerializer.Serialize(writer, new InferenceConfigCreateContainerDescriptor(InferenceConfigDescriptorAction), options);
			}
			else
			{
				writer.WritePropertyName("inference_config");
				JsonSerializer.Serialize(writer, InferenceConfigValue, options);
			}

			if (!string.IsNullOrEmpty(CompressedDefinitionValue))
			{
				writer.WritePropertyName("compressed_definition");
				writer.WriteStringValue(CompressedDefinitionValue);
			}

			if (!string.IsNullOrEmpty(DescriptionValue))
			{
				writer.WritePropertyName("description");
				writer.WriteStringValue(DescriptionValue);
			}

			if (InputDescriptor is not null)
			{
				writer.WritePropertyName("input");
				JsonSerializer.Serialize(writer, InputDescriptor, options);
			}
			else if (InputDescriptorAction is not null)
			{
				writer.WritePropertyName("input");
				JsonSerializer.Serialize(writer, new InputDescriptor(InputDescriptorAction), options);
			}
			else
			{
				writer.WritePropertyName("input");
				JsonSerializer.Serialize(writer, InputValue, options);
			}

			if (ModelSizeBytesValue.HasValue)
			{
				writer.WritePropertyName("model_size_bytes");
				writer.WriteNumberValue(ModelSizeBytesValue.Value);
			}

			if (ModelTypeValue is not null)
			{
				writer.WritePropertyName("model_type");
				JsonSerializer.Serialize(writer, ModelTypeValue, options);
			}

			if (TagsValue is not null)
			{
				writer.WritePropertyName("tags");
				JsonSerializer.Serialize(writer, TagsValue, options);
			}

			writer.WriteEndObject();
		}
	}
}